package com.zhanggm.student.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhanggm.student.entity.Hobby;
import com.zhanggm.student.mapper.HobbyMapper;
import com.zhanggm.student.service.IHobbyService;
import com.zhanggm.student.service.IStudentHobbyRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 爱好表 服务实现类
 * </p>
 *
 * @author zhanggm
 * @since 2020-10-21
 */
@Service
public class HobbyServiceImpl extends ServiceImpl<HobbyMapper, Hobby> implements IHobbyService {
    
    @Autowired
    private IStudentHobbyRelationService iStudentHobbyRelationService;
    
    @Override
    public String getNames(Integer stuId) {
        StringBuffer sb = new StringBuffer();
        //查询爱好Id
        List<Integer> hobbyIdList = iStudentHobbyRelationService.getHobbyIdListByStuId(stuId);
        //根据爱好Id查询爱好
        List<Hobby> hobbies = this.listByIds(hobbyIdList);
        //拼接爱好名称
        hobbies.forEach(h->{
            sb.append(h.getName()+"/");
        });
        return sb.toString();
    }
}
